/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apt;

import java.util.Scanner;

/**
 *
 * @author lhminh
 */
public class MangSoNguyen2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int[] a  = nhap();
        int b[] = new int[10];
        int[] c = new int[10];
        
        xuat(a);
        System.out.print("\nCac so chan trong mang la: ");
        lietKeChan(a);
    }

    public static int[] nhap() {
        Scanner scanner = new Scanner(System.in);

        int n = 0;
        int[] a;

        System.out.print("Nhap n: ");
        n = scanner.nextInt();
        a = new int[n];

//        System.out.println("Chieu dai cua mang la: " + a.length);

        for (int i = 0; i < a.length; i++) {
            System.out.print("Nhap a[" + i + "] = ");
            a[i] = scanner.nextInt();
        }
        
        return a;
    }
    
    public static void xuat(int[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }
    
    public static void lietKeChan(int[] a) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] % 2 == 0)
                System.out.print(a[i] + " ");
        }
    }
    
    public static int lonNhat(int[] a) {
        int kq = a[0];
        for (int i = 0; i < a.length; i++) {
            if (a[i] > kq)
                kq = a[i];
        }
        return kq;
    }
    
    // 1, 2, -3, 4, 55, 6
    public static int chanDau(int[] a) {
        
        for (int i = 0; i < a.length; i++) {
            if (a[i] % 2 == 0)
                return a[i];
        }
        
        return -1;
    }
    // 1, 2, -3, 4, 55, 6
    public static boolean tonTaiChan(int[] a) {
        boolean flag = false;
        
        for (int x : a) {
            if (x % 2 == 0)
                flag = true;
            if (flag == true)
                break;
        }
        
        return flag;
    }
    
    public static int demLe(int[] a) {
        int dem = 0;
        // for-each
        for (int x : a) {
            if (x % 2 != 0) 
                dem++;
        }
        return dem;
    }
    
    public static int viTriCoGiaTriNhoNhat(int[] a) {
        int lc = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] < a[lc]) 
                lc = i;
        }
        return lc;
    }
}
